12. Plugins
Heading
Plugins are one of the last vital concepts for webpack. The Webpack documentation explains them like this:
While loaders are used to transform certain types of modules, plugins can be leveraged to perform a wider range of tasks like bundle optimization, asset management and injection of environment variables.
So, pretty much anything that we need to do that falls outside the range of loaders will be accomplished with plugins.
Plugins can do all sorts of things, from automatically adding asset references to an html file (which we’ll cover in a second) to allowing for hot module replacement - which is used in React’s Create React App to create an auto updating development server.
FEND C04 L02 A06 Plugins
Quiz
SOLUTION:
PluginQuiz
SOLUTION:
LoaderQuiz
SOLUTION:
- Declare a new instance of the plugin in the plugins list
- Require the plugin from the node modules directory
- Install the plugin via yarn or npm
Interview Question
QUESTION: Interview Question
In javascript, when you see the "new" keyword, what does it do and what does it say about the thing it is being called on?
ANSWER:
Some words and concepts that should be part of your answer here are:
- The word instantiate, you create a new instance of the class
- We create instances from classes, so the thing it is called on must be a class
- If you want to get into the nitty gritty, you could talk about javascript pseudo classes and how the new keyword in javascript classes is really just syntactic sugar for javascript prototypes